package com.jwgf.group;

import android.os.Bundle;
import android.view.View;

import androidx.fragment.app.FragmentActivity;

import com.jwgf.adapter.ItemViewDelegate;
import com.jwgf.adapter.RecyclerViewHolder;
import com.jwgf.common.AppContext;
import com.jwgf.common.Utility;
import com.jwgf.smarowindingmachine_unity.R;
import com.jwgf.smarowindingmachine_unity.ui.GroupEditDialog;

public class GroupDelegate implements ItemViewDelegate {
    @Override
    public int getItemViewLayoutId() {
        return R.layout.navigation_button;
    }

    @Override
    public boolean isForViewType(Object item, int position) {
        return item instanceof Group;
    }

    @Override
    public void bindView(final RecyclerViewHolder holder, Object o, int position) {
        Group group = (Group) o;
        final Group attr = new Group(group.getStartSpindle(), group.getEndSpindle(), group.getId());
        holder.setText(R.id.btn, AppContext.getInstance().getString(R.string.group) + (position + 1) + ":" + attr.toString());
        holder.setOnClickListener(R.id.btn, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GroupEditDialog dialog = new GroupEditDialog();
                Bundle bd = new Bundle();
                bd.putSerializable(GroupEditDialog.GROUP, attr);
                dialog.setArguments(bd);
                FragmentActivity activity = Utility.ActivityUtils.getActivityFromView(holder.getItemView());
                dialog.show(activity.getSupportFragmentManager(), "group_edit");
            }
        });
    }



}
